package cn.xiangxiang.controller.goods;

import cn.xiangxiang.pojo.common.Result;
import cn.xiangxiang.pojo.goods.Brand;
import cn.xiangxiang.service.goods.BrandService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandContrller {

    @Reference
    private BrandService brandService;

    @RequestMapping("/findall")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public List<Brand> findAll(){
        return brandService.findall();
    }

    @RequestMapping("/findpage")
    @PreAuthorize("hasAuthority('findall')")
    public Page<Brand> findPage(Integer startpage,Integer pagesize){
        return brandService.findPage(startpage,pagesize);
    }

    @PostMapping("/findcondition")
    public List<Brand> findCondition(@RequestBody Brand brand){
        return brandService.findCondition(brand);
    }

    @PostMapping("/findconditionpage")
    public Page<Brand> findConditionPage(Integer startpage,Integer pagesize,@RequestBody Brand brand){
        return brandService.findConditionPage(startpage,pagesize,brand);
    }

    @GetMapping("/findbyid")
    @PreAuthorize("hasAuthority('select')")
    public Brand findById(Integer id){
        return brandService.findById(id);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return new Result();
    }

    @GetMapping("/delbyid")
    public Result delById(Integer id){
        brandService.delById(id);
        return new Result();
    }
}
